package com.seraph.td.http;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;




//http://edge.v.iask.com.sinastorage.com/85371372.mp4
public class SeraphHttpGet{
	static public void getToFile(String url,String fileName){
		HttpClient client = new DefaultHttpClient();
		HttpGet get = new HttpGet(url);
		FileOutputStream out;
		File file = null;
		try{
			HttpResponse response = client.execute(get);
			int code = response.getStatusLine().getStatusCode();
			System.out.println("response code ===="+code);
			if(response.getStatusLine().getStatusCode() == 200){
				file = new File(fileName);
				if(!file.exists()) 
					file.createNewFile();
				out = new FileOutputStream(file);
				InputStream in = response.getEntity().getContent();
				byte[] buffer = new byte[2048];
				int size = in.read(buffer);
				while(size > 0){
					out.write(buffer, 0, size);
					size = in.read(buffer);
				}
			}
			String value = file.getName();
//			mHandler.sendEmptyMessage(200);
		}catch (Exception e) {
			// TODO: handle exception
		}
		
	
	}
	static public void main(String[] args){
		getToFile("http://www.iqiyi.com/dianshiju/20121001/b4265b882e71cd58.html", "qiyi.html");
	}
}